package com.ihisun.tmhcms.config;

import com.google.common.base.Predicates;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Value("${swagger2.enable}")
    private boolean enable;

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("swagger-bootstrap-ui RESTful APIs")
                .description("swagger-bootstrap-ui")
                .termsOfServiceUrl("http://localhost:8764/swagger-ui.html")
                .contact("1933501072@qq.com")
                .version("1.0")
                .build();
    }

    @Bean
    public Docket project() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.projectcontroller");

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("项目相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }

    @Bean
    public Docket mechanism() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.mechanismcontroller");

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("机构相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }

    @Bean
    public Docket doctor() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.doctorcontroller");

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("医生相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }
    @Bean
    public Docket sysUser() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.sysusercontroller");
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("系统用户相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }

    @Bean
    public Docket order() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.ordercontroller");
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("订单相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }




    @Bean
    public Docket user() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.usercontroller");
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("用户相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }
    @Bean
    public Docket withdrawal() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.withdrawalcontroller");
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("提现相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }



    @Bean
    public Docket packages() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.giftbagcontroller");
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("礼包相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }

    @Bean
    public Docket city() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.citycontroller");
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("城市相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }
    @Bean
    public Docket opening() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.openingcontroller");
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("开通记录相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }
    @Bean
    public Docket activity() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.activitycontroller");
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("活动相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }

    @Bean
    public Docket sys() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.syscontroller");
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("系统设置Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }


    @Bean
    public Docket oss() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.ihisun.tmhcms.controller.osscontroller");
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("oss相关Api")
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(Predicates.or(selector1))
                .paths(PathSelectors.any())
                .build();

    }

}